package day8;

import java.io.*;
import java.util.*;

public class FileDemo7 {
    public static void main(String[] args) {

        File file = new File("E:\\vue\\yq_JAVA\\src\\main\\resources\\in.txt");
        File file2 = new File("E:\\vue\\yq_JAVA\\src\\main\\resources\\out.txt");
        System.out.println(file);

        List<String> wr = new ArrayList<>();
        StringBuilder wr3 = new StringBuilder();

        try (Reader r = new FileReader(file);
             BufferedReader br = new BufferedReader(r);
             ){
            String line = null;
            while ((line = br.readLine()) != null) {
                wr.add(line);
                wr3.append(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        String wr4 = wr3.toString();
        int[] id = new int[9];
        for (int i = 0; i < 9; i++){
            id[i] = wr3.indexOf(String.valueOf(i + 1));
        }

        Arrays.sort(id);
        String[] s = new String[9];
        for (int i = 0; i < 8; i++){
            s[i] = wr4.substring(id[i], id[i + 1]);
        }
        s[8] = wr4.substring(id[8]);

        Arrays.sort(s);
        for (String s1 : s) {
            System.out.println(s1);
        }

        Collections.sort(wr);

        try(Writer w = new FileWriter(file2)){
            for (String w2 : wr) {
                // System.out.println(name + "=" + p.getProperty(name));
                if (w2.contains("lisi")) {
                    // 修改成绩
                    System.out.println("修改好了");
                }
                w.write(w2 + "\r\n");

                w.flush();// 刷新缓冲
            }
            System.out.println("写回去了...");
        }catch (Exception e) {
            e.printStackTrace();
        }

    }
}
